﻿#include "stdafx.h"
#include "TupleType.h"

using namespace llvm;
AstType * TupleType::create(std::vector<AstType*>&& types)
{
	if (types.empty()) 
		return AstType::voidType;
	if (types.size() == 1)
		return types.front();

	auto *p=new TupleType();
	p->elements = std::move(types);
	return p;
}

llvm::Type * TupleType::llvmType(llvm::LLVMContext & context)
{
	if (_type) return _type;

	std::vector< llvm::Type* > types;
	for (auto &i : elements) {
		auto *p = i->llvmType(context);
		types.push_back(p);
	}
	_type = StructType::create(context, types, "tuple");
	return _type;
}

TupleType::TupleType() : AstType(AstType::TupleTyId) {
}
